using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
using Oops.Xna.Framework.Graphics;

namespace Oops.Xna.Framework.Content.Pipeline
{
	public class SkinningDataContent
	{
		private IList<Matrix> bindPose;
		private IList<Matrix> inverseBindPose;
		private IList<int> skeletonHierarchy;

		private TextureContent animationTexture;
		private IList<AnimationClip> animationClips;

		private IDictionary<string, int> boneIndices;
		
		public SkinningDataContent(
			IList<Matrix> bindPose,
			IList<Matrix> inverseBindPose,
			IList<int> skeletonHierarchy,
			TextureContent animationTexture,
			IList<AnimationClip> animationClips,
			IDictionary<string, int> boneIndices)
		{
			this.bindPose = bindPose;
			this.inverseBindPose = inverseBindPose;
			this.skeletonHierarchy = skeletonHierarchy;

			this.animationTexture = animationTexture;
			this.animationClips = animationClips;

			this.boneIndices = boneIndices;
		}

		public void Write(ContentWriter output)
		{
			output.WriteObject(this.bindPose);
			output.WriteObject(this.inverseBindPose);
			output.WriteObject(this.skeletonHierarchy);

			output.WriteObject(this.animationTexture);
			output.WriteObject(this.animationClips);

			output.WriteObject(this.boneIndices);
		}
	}

	[ContentTypeWriter()]
	public class SkinningDataContentWriter : ContentTypeWriter<SkinningDataContent>
	{
		#region ContentTypeWriter<SkinningDataContent> Members

		protected override void Write(ContentWriter output, SkinningDataContent value)
		{
			value.Write(output);
		}

		public override string GetRuntimeReader(TargetPlatform targetPlatform)
		{
			return "Oops.Xna.Framework.Graphics.SkinningDataReader, Oops.Xna.Framework";
		}

		public override string GetRuntimeType(TargetPlatform targetPlatform)
		{
			return "Oops.Xna.Framework.Graphics.SkinningData, Oops.Xna.Framework";
		}

		#endregion
	}

	[ContentTypeWriter()]
	public class KeyframeWriter : ContentTypeWriter<Keyframe>
	{
		#region ContentTypeWriter<Keyframe> Members

		protected override void Write(ContentWriter output, Keyframe value)
		{
			output.WriteObject(value.BoneIndex);
			output.WriteObject(value.Time);
			output.WriteObject(value.Transform);
		}

		public override string GetRuntimeReader(TargetPlatform targetPlatform)
		{
			return "Oops.Xna.Framework.Graphics.KeyframeReader, Oops.Xna.Framework";
		}

		#endregion
	}

	[ContentTypeWriter()]
	public class AnimationClipWriter : ContentTypeWriter<AnimationClip>
	{
		#region ContentTypeWriter<AnimationClip> Members

		protected override void Write(ContentWriter output, AnimationClip value)
		{
			output.Write(value.Name);
			output.WriteObject(value.Duration);
			output.WriteObject(value.FrameRate);
			output.WriteObject(value.Keyframes);
			output.WriteObject(value.StartRow);
			output.WriteObject(value.EndRow);
		}

		public override string GetRuntimeReader(TargetPlatform targetPlatform)
		{
			return "Oops.Xna.Framework.Graphics.AnimationClipReader, Oops.Xna.Framework";
		}

		#endregion
	}
}
